﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using HomeDmsUtils;

namespace HomeDms.Imaging
{
    public partial class QualityPictureBox : PictureBox
    {
        public QualityPictureBox()
        {
            InitializeComponent();
        }

        Image originalImage = null;

        public Image OriginalImage
        {
            get
            {
                return originalImage;
            }
            set
            {                
                originalImage = value;
                if (originalImage != null)
                    Image = originalImage.BuildThumbnailImage(ClientSize);
            }
        }

        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
            if (originalImage != null)
            {
                Image = originalImage.BuildThumbnailImage(ClientSize);
            }
        }

        //public Size GetZoomedSize()
        //{
        //    Size size = new Size();
        //    float Wrate = (float)ClientSize.Width / originalImage.Size.Width;
        //    float Hrate = (float)ClientSize.Height / originalImage.Size.Height;
        //    float rate = Math.Min(Wrate, Hrate);
        //    size.Width = (int)Math.Round(originalImage.Width * rate);
        //    size.Height = (int)Math.Round(originalImage.Height * rate);
        //    return size;
        //}

        //private Image BuildThumbnailImage()
        //{
        //    Size zsize = GetZoomedSize();
        //    Image thumb = new Bitmap(zsize.Width, zsize.Height, originalImage.PixelFormat);
        //    Graphics g = Graphics.FromImage(thumb);
        //    g.CompositingQuality = CompositingQuality.HighQuality;
        //    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
        //    g.SmoothingMode = SmoothingMode.HighQuality;
        //    Rectangle rect = new Rectangle(Point.Empty, zsize); 
        //    g.DrawImage(originalImage, rect);
        //    return thumb;
        //}        
    }
}
